package main;

import java.util.Scanner;

import shop.*;

public class MainFuction {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        Mall test = new Mall();
        //展示商品
        test.showGoods();

        while (true) {
            System.out.println("请输入你要进行的操作信息：");
            System.out.println("exit:退出");
            System.out.println("search:查找商品");
            System.out.println("buy:购买商品");
            System.out.println("其他任意键:进入购物车");
            
            String str = sc.nextLine();
            if ("exit".equals(str))
                break;
            else if ("search".equals(str)) {
                System.out.println("根据关键字查询or类型查询");
                str = sc.nextLine();
                if ("关键字".equals(str)) {
                    System.out.println("请输入查询商品的关键字");
                    String search = sc.nextLine();
                    test.searchWord(search);
                } else if ("类型".equals(str)) {
                    System.out.println("输入查询商品的类型");
                    String search = sc.nextLine();
                    test.searchType(search);
                }
                continue;
            } else if("buy".equals(str)){
                System.out.println("请输入你要购买商品的ID：");
                str = sc.nextLine();
                String[] arr = str.split("\\s+");

                //通过输入的ID，加入商品
                for (int i = 0; i < arr.length; i++) {
                   int flag = test.putinCart(Integer.parseInt(arr[i]));
                   if(flag == 0)
                	   System.out.println("不存在该商品ID:"+arr[i]+"，请输入正确的商品ID");
                }
                
            }
            
            else {
            	while (true) {
                    //展示购物车信息
                    Mall.cart.showGoodsItem();


                    System.out.println("请输入你对购物车的操作:");
                    System.out.println("1:结算订单");
                    System.out.println("2:修改商品数量");
                    System.out.println("3:将商品移出购物车:");
                    System.out.println("除此之外任意键:返回商城");

                    String op = sc.nextLine();
                    if ("1".equals(op)) {
                        Mall.cart.settlement();
                    } else if ("2".equals(op)) {
                        System.out.println("请输入商品ID及要修改的数量");
                        Mall.cart.setNum(sc.nextInt(), sc.nextInt());
                        sc.nextLine();
                    } else if ("3".equals(op)) {
                        System.out.println("请输入要移除商品的ID");
                        Mall.cart.remove(sc.nextInt());
                        sc.nextLine();
                    } else {
                        //展示商品
                        test.showGoods();
                        break;
                    }
                }
            }

        }

        sc.close();
    }

}
